/*
 Copyright (C) 2013 Yuyao Liang

 This source code is release under the BSD License.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
 

 */
package com.googlecode.stereoplot;

/**
 * @author lianyuy
 * 
 */
public class StereoPlotDataSeriesFactory {

	public StereoPlotDataSeriesFactory() {
	}

	public static StereoPlotDataSeries createStereoPlotDataSeries(String key,
			SymmetryType type, double azimuthOffset, int azimuthStep,
			int deviateStep, double[] values) {
		StereoPlotDataSeries series = new StereoPlotDataSeries(key, type,
				azimuthOffset);

		double azimuthRange = 0;
		switch (type) {
		case None:
			azimuthRange = 2 * Math.PI;
			break;
		case X_Symmetry:
		case Y_Symmetry:
			azimuthRange = Math.PI;
			break;
		case Center_Symmetry:
			azimuthRange = Math.PI / 2;
			break;
		default:
			break;
		}

		double azimuthStepSize = azimuthRange / azimuthStep;
		double deviateRange = Math.PI / 2;
		double deviateStepSize = deviateRange / deviateStep;

		for (int j = 0; j < deviateStep; j++) {
			double deviate = deviateStepSize * j;

			for (int i = 0; i < azimuthStep; i++) {
				double azimuth = azimuthStepSize * i;
				int index = j * azimuthStep + i;

				series.add(new StereoPlotDataItem(
						index,
						new StereoPlotDataPoint(azimuth, deviate, values[index])));
			}
		}
		return series;
	}

	public static StereoPlotDataQuickSeries createStereoPlotDataQuickSeries(
			String key, SymmetryType type, double azimuthOffset,
			int azimuthStep, int deviateStep, double[] values) {
		StereoPlotDataQuickSeries series = new StereoPlotDataQuickSeries(key,
				type, azimuthOffset, azimuthStep, deviateStep);

		double azimuthRange = 0;
		switch (type) {
		case None:
			azimuthRange = 2 * Math.PI;
			break;
		case X_Symmetry:
		case Y_Symmetry:
			azimuthRange = Math.PI;
			break;
		case Center_Symmetry:
			azimuthRange = Math.PI / 2;
			break;
		default:
			break;
		}

		double azimuthStepSize = azimuthRange / (azimuthStep - 1);
		double deviateRange = Math.PI / 2;
		double deviateStepSize = deviateRange / (deviateStep - 1);

		for (int j = 0; j < deviateStep; j++) {
			double deviate = deviateStepSize * j;

			for (int i = 0; i < azimuthStep; i++) {
				double azimuth = azimuthStepSize * i;
				int index = j * azimuthStep + i;

				series.add(new StereoPlotDataItem(
						index,
						new StereoPlotDataPoint(azimuth, deviate, values[index])));
			}
		}
		return series;
	}
}
